package com.wq.handlers;

public class BaseContext {
    // 定义一个静态线程变量，用于保存当前用户的id，final保证threadLocal不可修改，static使所有实例共享同一个threadLocal
    private static final ThreadLocal<Long> threadLocal = new ThreadLocal<>();


    // 获取当前用户的id
    public static Long getCurrentId(){
        return threadLocal.get();
    }

    // 设置当前用户的id
    public static void setCurrentId(Long id){
        threadLocal.set(id);
    }
    
    // 清除所有线程变量
    public static void clear(){
        threadLocal.remove();
    }
}
